package com.bsg.upm.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bsg.upm.http.RespJson;
import com.bsg.upm.http.RespJsonFactory;
import com.bsg.upm.service.MonitorSiteService;

/**
 * 
 * @author yucs
 *
 */

@Controller
@RequestMapping("/v1.0/monitor/site")
public class MonitorSiteController {
	@Resource
	MonitorSiteService monitorSiteService;

	@RequestMapping(value = "/{site_id}/clusterinfos", method = RequestMethod.GET)
	@ResponseBody
	public RespJson getCpuInfo(@PathVariable("site_id") String siteId, HttpServletResponse response) {
		RespJson respJson = null;
		try {
			respJson = monitorSiteService.getClusterInfo(siteId);
			response.setStatus(respJson.getStatus());
		} catch (Exception e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}


	@RequestMapping(value = "/cluster/{cluster_id}/hostinfos", method = RequestMethod.GET)
	@ResponseBody
	public RespJson getCluterHostInfo(@PathVariable("cluster_id") String clusterId, HttpServletResponse response) {
		RespJson respJson = null;
		try {
			respJson = monitorSiteService.getHostInfo(clusterId);
			response.setStatus(respJson.getStatus());
		} catch (Exception e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}

}
